package com.lin.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lin.entity.User;
import com.lin.entity.Userinfo;
import com.lin.entity.UserinfoDto;
import com.lin.mapper.UserinfoMapper;
import com.lin.service.UserinfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lin
 * @since 2022-06-17
 */
@Service
public class UserinfoServiceImpl extends ServiceImpl<UserinfoMapper, Userinfo> implements UserinfoService {

    @Resource
    UserServiceImpl userService;

    @Resource
    UserinfoMapper userinfoMapper;

    @Override
    public Page<UserinfoDto> getUserinfo(Integer page, Integer size, Integer condition, String key) {
        Page<UserinfoDto> page1=new Page<>(page,size);

        return userinfoMapper.getUserinfo(page1, condition, key);
    }

    @Override
    public Boolean addUserinfo(UserinfoDto dto) {
        User user = new User(null, dto.getUsername(), dto.getPassword(), null);//默认普通用户
        userService.saveUser(user);
        Userinfo userinfo = new Userinfo(user.getUid(), dto.getName(), dto.getDepartmentDid(), dto.getJob(), dto.getManager(), dto.getDescription());
        return this.save(userinfo);
    }

    @Override
    public Boolean updateUserinfo(Userinfo userinfo) {
        return this.updateById(userinfo);
    }

    @Override
    public Boolean removeUserinfo(Integer uid) {
        userService.removeById(uid);
        return this.removeById(uid);
    }
}
